package com.lx.springmvcproject2.controller;


import com.lx.springmvcproject2.entity.Goods;
import com.lx.springmvcproject2.entity.ResultBody;
import com.lx.springmvcproject2.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lx
 * @since 2021-11-03
 */
@Api(tags = "货物接口")
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @ApiOperation(value ="新增一个货物")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "good", value = "货物类", required = true, dataType = "Goods"),
    })
    @PostMapping("/add")
    public ResultBody add(@RequestParam("good")Goods goods)
    {
        boolean col=goodsService.save(goods);
        return ResultBody.success();
    }

    @ApiOperation(value ="获取所有货物")
    @GetMapping("/list")
    public ResultBody list()
    {
        return ResultBody.success(goodsService.list());
    }

    public ResultBody getGood() {
        Goods goods = new Goods();
        return ResultBody.success(goods);
    }

    @ApiOperation(value ="删除一个货物")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "good", value = "货物类带id即可", required = true, dataType = "Goods"),
    })
    @DeleteMapping("del")
    public ResultBody del(@RequestParam("good")Goods goods)
    {
        return ResultBody.success(goodsService.removeById(goods));
    }

    @ApiOperation(value ="修改货物信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "good", value = "货物类", required = true, dataType = "Goods"),
    })
    @PutMapping("/update")
    public ResultBody update(@RequestParam("good")Goods goods)
    {
        return ResultBody.success(goodsService.updateById(goods));
    }
}
